  /**
给你一个二叉树的根节点 root ， 检查它是否轴对称。 

 

 示例 1： 
 
 
输入：root = [1,2,2,3,4,4,3]
输出：true
 

 示例 2： 
 
 
输入：root = [1,2,2,null,3,null,3]
输出：false
 

 

 提示： 

 
 树中节点数目在范围 [1, 1000] 内 
 -100 <= Node.val <= 100 
 

 

 进阶：你可以运用递归和迭代两种方法解决这个问题吗？ 

 Related Topics 树 深度优先搜索 广度优先搜索 二叉树 👍 2036 👎 0

*/
  
package fl;

/**
* @Title 对称二叉树
* @Date 2022-07-30 21:52:03
*/

public class P101_SymmetricTree {
    public static void main(String[] args) {
        Solution solution = new P101_SymmetricTree().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */

public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
class Solution {
    public boolean isSymmetric(TreeNode root) {
        return isSame(root.left,root.right);
    }
    boolean isSame(TreeNode l,TreeNode r){
       if(l == null && r == null){
           return true;
       }
       if(l == null || r == null){
           return false;
       }
        if(l.val != r.val){
            return false;
        }
       return isSame(l.right,r.left) && isSame(l.left,r.right);
    }

}
//leetcode submit region end(Prohibit modification and deletion)

}